﻿using System.Collections.Generic;
using UnityEngine;

namespace JH
{
    /// <summary>
    ///  Vector2类型按Y值进行排序的比较器
    /// </summary>
    public class Vector2ComparerByY : IComparer<Vector2>, IEqualityComparer<Vector2>
    {
        /// <summary>
        ///  比较器
        /// </summary>
        public static readonly Vector2ComparerByY Comparer = new();

        /// <summary>
        ///  Y值比较器，用于对数据点按Y值进行排序
        /// </summary>
        public int Compare(Vector2 a, Vector2 b)
        {
            // 按Y值进行比较
            return a.y.CompareTo(b.y);
        }

        public bool Equals(Vector2 a, Vector2 b)
        {
            // 只比较Y值是否相等
            return a.y.Equals(b.y);
        }

        public int GetHashCode(Vector2 obj)
        {
            // 使用Y值的哈希码作为对象的哈希码
            return obj.y.GetHashCode();
        }
    }
}